package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapePlot;
import com.ruoyi.grape.service.IGrapePlotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地块信息Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/plot")
public class GrapePlotController extends BaseController
{
    @Autowired
    private IGrapePlotService grapePlotService;

    /**
     * 查询地块信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:plot:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapePlot grapePlot)
    {
        startPage();
        List<GrapePlot> list = grapePlotService.selectGrapePlotList(grapePlot);
        return getDataTable(list);
    }

    /**
     * 导出地块信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:plot:export')")
    @Log(title = "地块信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapePlot grapePlot)
    {
        List<GrapePlot> list = grapePlotService.selectGrapePlotList(grapePlot);
        ExcelUtil<GrapePlot> util = new ExcelUtil<GrapePlot>(GrapePlot.class);
        util.exportExcel(response, list, "地块信息数据");
    }

    /**
     * 获取地块信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plot:query')")
    @GetMapping(value = "/{plotId}")
    public AjaxResult getInfo(@PathVariable("plotId") Long plotId)
    {
        return success(grapePlotService.selectGrapePlotByPlotId(plotId));
    }

    /**
     * 新增地块信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plot:add')")
    @Log(title = "地块信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapePlot grapePlot)
    {
        return toAjax(grapePlotService.insertGrapePlot(grapePlot));
    }

    /**
     * 修改地块信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plot:edit')")
    @Log(title = "地块信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapePlot grapePlot)
    {
        return toAjax(grapePlotService.updateGrapePlot(grapePlot));
    }

    /**
     * 删除地块信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plot:remove')")
    @Log(title = "地块信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{plotIds}")
    public AjaxResult remove(@PathVariable Long[] plotIds)
    {
        return toAjax(grapePlotService.deleteGrapePlotByPlotIds(plotIds));
    }
}
